package cn.gson.crm.model.service;

import cn.gson.crm.model.dao.QuestionsDao;
import cn.gson.crm.model.mapper.QuestionsMapper;
import cn.gson.crm.model.pojos.Customer;
import cn.gson.crm.model.pojos.CustomerService;
import cn.gson.crm.model.pojos.Questions;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.hibernate.cfg.QuerySecondPass;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@Transactional(rollbackFor = Exception.class)
public class QuestionsService {
    @Autowired
    QuestionsMapper questionsMapper;
    @Autowired
    QuestionsDao questionsDao;
    //查询当前人所有客户投诉记录
    public Map<String,Object> selectcom( Integer page, Integer size){
        List<Questions> complaints2=questionsMapper.selectqus();
        Page<Object> obj = PageHelper.startPage(page, size);
        List<Questions> complaints=questionsMapper.selectqus();
        Map<String,Object> map = new HashMap<>();
        map.put("total",obj.getTotal());
        map.put("rows",complaints);
        map.put("tong",complaints2);
        return map;
    };
    //条件查询
    public Map<String,Object> selectwhere(  String where,Integer page, Integer size){
        Page<Object> obj = PageHelper.startPage(page, size);
        List<Questions> complaints=questionsMapper.selectwhere(where);
        Map<String,Object> map = new HashMap<>();
        map.put("total",obj.getTotal());
        map.put("rows",complaints);
        return map;
    };
    //根据时间查询
    public Map<String,Object> selecttime( String statr, String endtime,Integer page, Integer size){
        Page<Object> obj = PageHelper.startPage(page, size);
        List<Questions> complaints=questionsMapper.selecttime(statr,endtime);
        Map<String,Object> map = new HashMap<>();
        map.put("total",obj.getTotal());
        map.put("rows",complaints);
        return map;
    };
    //新增
    public void  savecom(Questions questions){
        questionsDao.save(questions);
    }
    //删除
    public void deletCustomerService(Questions questions){
        questionsDao.delete(questions);
    }

}
